open (employees,"some.txt" ) || die "can not open ";
print "names that end in 'son' \n";


while(<employees>)
{
$total_employees++;
chomp;
($name,$age,$dept,$salary) = split(/:/);

if ($name =~ /son$/)
{
print "$name \n";
}




#>> employee age is under 40 count him or her and add his or her salary to the sum of such salaries 

if ($age < 40)
{
 $under_40++;
 $salary_sum += $salary;
#>>  if he salary was over 40,000 count him her and add his or her salary to the hash of such people  
if ($salary >40000)
{
$sublist{$name} = $salary;
}
}
}
if($total_employees > 0 )
{
if($under_40 > 0)
{
# >> computes and display the % the of employee under 40 and their  average salaries 
$percent = 100 * $under_40 / $total_employees;
print "\n percent of employee under 40 is :$percent \n";
$avg = $salary_sum / $under_40;
print "average salary of employee under 40 is :$avg \n";
if (keys(%sublist))
{
print "sorted list of employees under 40","with salaries  > \$40,000 \n";
@sorted_names =sort (keys(%sublist));
print "\n name \t\t salary \n";
foreach $name (@sorted_names)
{
print "$name \t \$$sublist{$name} \n";
}
}
else 
{
print "there were no employee under 40  who earned over 40000 \n";
}
}
else
{
print "there were no employee under 40\n ";
}
}
else 
{
print "there were no employeees\n" ;
} 




 


